class Solution {
public:
    int maximumSum(vector<int>& nums) {
        vector<int>g[110];
        int n = nums.size();
        int ma = 0;
        for (auto x : nums) {
            int temp = x;
            int sum = 0;
            while (temp) {
                sum += temp % 10;
                temp /= 10;
            }
            g[sum].push_back(x);
        }
        for (int i = 0; i < 82; i++) {
            sort(g[i].begin(), g[i].end());
            int m = g[i].size();
            if (m >= 2)ma = max(ma, g[i][m - 2] + g[i][m - 1]);
        }
        if (!ma)return -1;
        return ma;
    }
};